package com.coder520.servicestudy;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by huang on 2017/7/6.
 */

public class StudentService extends Service {
    private static final String TAG = StudentService.class.getSimpleName();
    private MyBinder mBinder = new MyBinder();
    private Student mStudent;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "coder520... onCreate Called");
        stopSelf();
    }

    public void addStudent(Student student) {
        this.mStudent = student;
    }

    public Student getStudent() {
        return mStudent;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "coder520... onStartCommand Called");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "coder520... onDestroy Called");
        super.onDestroy();
    }

    class MyBinder extends Binder {
        public StudentService getService() {
            return StudentService.this;
        }
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "coder520.... onBind called");
        return mBinder;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.d(TAG, "coder520.... onUnbind called");
        return super.onUnbind(intent);
    }
}
